<?php
/**
 * Created by PhpStorm.
 * User: CPR007
 * Date: 2020/12/25
 * Time: 9:56
 */
require_once './coreBase.php';

class  clearOrder extends coreBase {

    public function __construct() {
        parent::__construct();
        $this->_configInfo['redis']['db'] = 0;
        $this->getRedisInstance($this->_configInfo['redis']);
    }

    public function clear()
    {
        $weChatPayUsers = self::$redisInstance->hGetAll('createPinkHash');
        if (!empty($weChatPayUsers)) {
            foreach ($weChatPayUsers as $key => $time) {
                if ((time() - intval($time)) >= 55) {
                    if (self::$redisInstance->hDel('createPinkHash', $key)) {
                        [$uid, $pinkId] = explode('-', $key);
                        //减员
                        $pre = self::$redisInstance->get("create_{$pinkId}");
                        self::$redisInstance->decr("create_{$pinkId}");
                        $next = self::$redisInstance->get("create_{$pinkId}");
                        $this->writeLog("{$uid}--2--微信支付失败,参团减员: create_{$pinkId}, 减员前:{$pre},减员后:{$next}", 3);
                    }
                }
            }
        }
    }

}